<template>
    <div class="numbox">
        <div class="mui-numbox"  data-numbox-min='1' >
            <!-- "-"按钮，点击可减小当前数值 -->
            <button class="mui-btn mui-numbox-btn-minus" type="button">-</button>
            <input class="mui-numbox-input" type="number" :value="count" @change="getcount" ref="numbox" readonly/>
            <!-- "+"按钮，点击可增大当前数值 -->
            <button class="mui-btn mui-numbox-btn-plus" type="button">+</button>
        </div>
    </div>
</template>

<script>
import mui from "../../../lib/mui/js/mui.min.js"
export default {
    mounted(){
        mui(".mui-numbox").numbox()
    },
    methods:{
        getcount(){
            this.$emit("getcount",mui(".mui-numbox").numbox().getValue())
            // 获取当前组件中，商品id和对应的双联，通过mutation去更新到car中
            this.$store.commit("updateGoodsInfo",{
                id:this.goodsid,
                count:this.$refs.numbox.value
            })
        }
    },
    props: ["max","count","goodsid"],
    watch:{
        //父组件绑定max属性给子组件，max属性值发生变化，watch监测该属性变化，触发该事件
        max(newVal){
            mui('.mui-numbox').numbox().setOption('max',newVal)
        }
    }
  
}
</script>

<style lang="less" scoped>
    .numbox{
        display: inline-block;
    }
</style>
